import loginRequest from "@/utils/loginRequest";

export interface LoginModel {
    phone: string;
    password: string;
}
export interface resLoginModel {
    name: string;
    nickName: string;
    token: string;
    userId: number;
}

export interface resUserInfo {
    headImg: string;
    id: number;
    name: string;
    nickName: string;
    loginName: string;
}

export interface registerModel {
    phone: string; // 手机号
    code: string; // 验证码
    password: string; // 密码
    repassword: string; // 确认密码
    isAgreen: boolean; // 是否统一协议
}

export default {
    //登录
    reqLogin(formData: LoginModel) {
        return loginRequest.post<any, resLoginModel>(
            `/user/passport/login`,
            formData
        );
    },
    //获取用户信息
    getUserInfo() {
        return loginRequest.get<any, resUserInfo>(
            `/user/passport/auth/getUserInfo`
        );
    },
    //退出登录
    logout() {
        // 也是通过token来登出的
        return loginRequest.get<any, null>(`/user/passport/logout`);
    },
    // 注册
    // /api/user/passport/register
    reqRegister(formData: registerModel) {
        return loginRequest.post(`/user/passport/register`, formData);
    },

    // 获取验证码
    // /api/user/passport/sendCode/{phone}
    reqCode(phone: string) {
        return loginRequest.get(`/user/passport/sendCode/${phone}`);
    },
};
